/*
 * @Author: wangchao
 * @Date: 2024-08-28 08:10:15
 * @LastEditors: wangchao
 * @LastEditTime: 2024-10-10 13:22:55
 * @FilePath: \JD-RTT-Driver\applications\u_soc.c
 * @Description:
 * Copyright (c) 2024 by Bingshan Guardian, All Rights Reserved.
 */

#include "u_soc.h"

#define DBG_TAG "SOC"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>

static float calculate_soc_value(float f_ocv)
{
    float f_soc = -20671.0f * f_ocv * f_ocv * f_ocv * f_ocv + 107658.0f * f_ocv * f_ocv * f_ocv - 208575.0f * f_ocv * f_ocv + 178399.0f * f_ocv - 56903.5f;
    return f_soc;
}

extern rt_uint16_t get_eocv(rt_uint8_t chx);

rt_uint16_t get_bms_soc(rt_uint8_t chx)
{
    rt_uint16_t ocv = get_eocv(chx);
    float f_ocv = (float)(ocv) / 10000.0;
    //
    float soc = calculate_soc_value(f_ocv);
    // soc = 68.8% (保留一位小数)
    rt_uint16_t uint_soc = (rt_uint16_t)(soc * 1000.0);
    return uint_soc;
}

void print_soc(void)
{
    rt_uint16_t soc_a = get_bms_soc(1);
    rt_uint16_t soc_b = get_bms_soc(2);
    LOG_I("current a_soc:%d b_soc:%d", soc_a, soc_b);
}

MSH_CMD_EXPORT(print_soc, print soc);